<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j"
	template="/WEB-INF/templates/template.xhtml">
	<ui:param name="activeView" value="ambito" />
	<ui:define name="breadcrumb">
		<ui:include src="breadcrumb.xhtml" />
	</ui:define>
	<ui:define name="menu">
		<ui:include src="/admin/menu.xhtml" />
	</ui:define>
	<ui:define name="title">#{messages.usersCreate}</ui:define>
	<ui:define name="content">
		<f:metadata>  
   			<f:event type="preRenderView" listener="#{createUserBean.clearData}"/>  
		</f:metadata>	
		<h:form method="post">
			<rich:graphValidator value="#{createUserBean}" id="gv">
				<rich:panel header="#{messages.userData}">
					<rich:messages for="gv" 
						infoClass="green" 
						errorClass="red" 
						globalOnly="false" 
						ajaxRendered="true" />
					<rich:messages for="gv" 
						infoClass="green" 
						errorClass="red" 
						globalOnly="true" 
						ajaxRendered="true" />
					<h:panelGrid columns="3">
						<h:outputLabel for="username" value="#{messages.loginUsername}:" styleClass="normal" />
						<h:inputText id="username" value="#{createUserBean.username}" autocomplete="off">
							<rich:validator/>
						</h:inputText>
						<rich:message for="username"/>
						
						<h:outputLabel for="password" value="#{messages.loginPassword}:" styleClass="normal" />
						<h:inputSecret id="password" value="#{createUserBean.password}" autocomplete="off">
							<rich:validator/>
						</h:inputSecret>
						<rich:message for="password"/>
						
						<h:outputLabel value="#{messages.loginPasswordRetry}:" styleClass="normal" />
						<h:inputSecret id="passwordRetry" value="#{createUserBean.passwordRetry}" autocomplete="off">
							<rich:validator/>
						</h:inputSecret>
						<rich:message for="passwordRetry"/>
					</h:panelGrid>
	
					<rich:panel style="width:560px;">
			            <f:facet name="header">
			                <h:outputText value="#{messages.loginUserRoles}"></h:outputText>
			            </f:facet>
			            <rich:pickList value="#{createUserBean.selectedGroups}" 
			            	sourceCaption="#{messages.loginAvailableRoles}" 
			            	targetCaption="#{messages.loginSelectedRoles}" 
			            	listWidth="165px" 
			            	listHeight="100px" 
			            	orderable="true"
			            	addAllText="#{messages.addAllText}"
			            	addText="#{messages.addText}"
			            	removeText="#{messages.removeText}"
			            	removeAllText="#{messages.removeAllText}"
			            	downText="#{messages.downText}"
			            	downBottomText="#{messages.downBottomText}"
			            	upText="#{messages.upText}"
			            	upTopText="#{messages.upTopText}">

			                <f:selectItems value="#{createUserBean.groups}" var="group" 
			                	itemValue="#{group}"
			                	itemLabel="#{group.name}" />
			            </rich:pickList>
					</rich:panel>
					
					<rich:panel style="width:560px;">
			            <f:facet name="header">
			                <h:outputText value="#{messages.loginUserAuthorities}"></h:outputText>
			            </f:facet>
			            <rich:pickList value="#{createUserBean.selectedAuthorities}" 
			            	sourceCaption="#{messages.loginAvailableAuthorities}" 
			            	targetCaption="#{messages.loginSelectedAuthorities}" 
			            	listWidth="165px" 
			            	listHeight="100px" 
			            	orderable="true"
			            	addAllText="#{messages.addAllText}"
			            	addText="#{messages.addText}"
			            	removeText="#{messages.removeText}"
			            	removeAllText="#{messages.removeAllText}"
			            	downText="#{messages.downText}"
			            	downBottomText="#{messages.downBottomText}"
			            	upText="#{messages.upText}"
			            	upTopText="#{messages.upTopText}">

			                <f:selectItems value="#{createUserBean.authorities}" var="auth" 
			                	itemValue="#{auth}"
			                	itemLabel="#{messages[auth]}" />
			            </rich:pickList>
					</rich:panel>
				</rich:panel>
	        	<h:panelGrid columns="2">
					<h:commandButton value="#{messages.userCreateSubmit}" 
						action="#{createUserBean.createUser}"/>
					<h:commandButton value="#{messages.cancel}" 
						action="#{createUserBean.cancel}" 
						immediate="true"/>
				</h:panelGrid>					
			</rich:graphValidator>
		</h:form>
	</ui:define>
</ui:composition>